package io.xxx.omni.oss.custom

import com.google.gson.JsonObject
import io.xxx.omni.oss.common.format
import io.xxx.omni.oss.common.toJsonString
import io.xxx.omni.oss.common.toLocalDateTime
import io.xxx.omni.oss.domain.Document
import io.xxx.omni.oss.domain.DocumentType

// https://open.aikucun.com/?docType=1&id=2
@Suppress("unused")
class AkcRefundSynchronizer : AkcSynchronizer() {

    override val documentType = DocumentType.REFUND

    override val interfaceName = "aikucun.aftersale.order.list"

    override fun getCount(context: Context, response: JsonObject): Int {
        return response["totalCount"].asInt
    }

    override fun buildDocuments(context: Context, response: JsonObject): List<Document> {
        return response
            .getAsJsonArray("result")
            .map {
                it as JsonObject
                Document(
                    it["adNo"].asString,
                    it["orderId"].asString,
                    it["status"].asString,
                    it.toJsonString(),
                    it["createTime"].toLocalDateTime(),
                    it["updateTime"].toLocalDateTime(),
                )
            }
    }

    override fun buildRequest(context: Context, pageNo: Int): Map<String, Any> {
        return mapOf(
            "startModified" to context.startTime.format(),
            "endModified" to context.endTime.format(),
            "pageNum" to pageNo,
            "pageSize" to pageSize,
        )
    }
}